package com.neegix.development.api.infrastructure.repository.impl;

import com.neegix.application.query.NebulaSQL;
import com.neegix.base.PageVO;
import com.neegix.development.api.application.assembler.ApiAssembler;
import com.neegix.development.api.application.repository.ApiQueryRepository;
import com.neegix.development.api.infrastructure.repository.dataobject.ApiDO;
import com.neegix.development.api.infrastructure.repository.mapper.ApiMapper;
import com.neegix.development.api.infrastructure.repository.mapper.customized.ApiCustomizedMapper;
import com.neegix.development.api.interfaces.vo.ApiListVO;
import com.neegix.development.api.interfaces.vo.ApiVO;
import com.neegix.development.menu.infrastructure.repository.mapper.MenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-11-22 11:43:14
  */

@Repository
public class ApiQueryRepositoryImpl implements ApiQueryRepository {

    @Autowired
    private ApiMapper apiMapper;

    @Autowired
    private ApiCustomizedMapper apiCustomizedMapper;

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public Optional<ApiVO> findById(Long id) {
//        ApiDO apiDO = apiMapper.selectByPrimaryKey(id);
//        MenuDO menuDO = menuMapper.selectByPrimaryKey(apiDO.getModule());
//        ApiVO apiVO = ApiAssembler.INSTANCE.covertVO(ApiConverter.INSTANCE.covertDTO(apiDO));
//        apiVO.setModuleName(menuDO.getName());
        return Optional.empty();
    }


     @Override
    public Integer selectCount(List<Long> ids) {
        return apiCustomizedMapper.selectCountByIds(ids);
    }

    @Override
    public PageVO<ApiListVO> findPage(Integer currentPage, Integer pageSize, NebulaSQL nebulaSQL) {
        nebulaSQL.setPager(currentPage, pageSize);
        List<ApiDO> result = apiMapper.selectList(nebulaSQL);
        Long total = apiMapper.selectCount(nebulaSQL);
        PageVO<ApiListVO> page = new PageVO<>(currentPage, pageSize);
        page.setTotal(total);
        page.setResult(ApiAssembler.INSTANCE.convertToListVO(result));
        return page;
    }

 }
